package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.User;
import com.itheima.reggie.dto.LoginDto;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    //发送短信
    @PostMapping("/user/sendMsg")
    //接受参数
    public ResultInfo sendMsg(@RequestBody User user) {
        //调用发消息方法
        userService.sendMsg(user.getPhone());
        //发送成功
        return ResultInfo.success();
    }

    // 登录功能
    @PostMapping("/user/login")
    public ResultInfo lonin(@RequestBody LoginDto loginDto) {

        String token =userService.login(loginDto.getPhone(),loginDto.getCode());

        return ResultInfo.success(token);
    }

    // 用户退出
    @PostMapping("/user/logout")
    public ResultInfo logout(){
        return ResultInfo.success();
    }

}
